/**   
 * @Title: ConnectForLogin.java 
 * @Package cn.edu.cdtu.healthclient.connect 
 * @Description: TODO 
 * @author 
 * @date 
 * @version V0.0   
 */
package cn.edu.cdtu.healthclient.connect;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import cn.edu.cdtu.healthclient.domain.LoginJson;
import cn.edu.cdtu.healthclient.utils.ConnectUtil;

import com.google.gson.Gson;

/** 
 * @ClassName: ConnectForLogin 
 * @Description: TODO
 * @author 
 * @date 
 *  
 */
public class ConnectForLogin 
{
	/**
	 * 
	 * @Title: connect 
	 * @Description: TODO
	 * @return LoginJson
	 * @throws 
	 *
	 * @param account
	 * @param password
	 * @param httpClient
	 * @return
	 * @throws Exception
	 */
	public static LoginJson connect(String account,String password
			,HttpClient httpClient) throws Exception
	{
		LoginJson loginJson = null;
		HttpGet httpGet = new HttpGet(
				ConnectUtil.HealthServerContect.SERVER_URL
				+ ConnectUtil.HealthServerContect.LOGIN_SERVLET
				+ "?" + ConnectUtil.LoginPargrams.Pargram.LOGIN_ACCOUNT
				+ "=" + account + "&"
				+ ConnectUtil.LoginPargrams.Pargram.LOGIN_PASSWORD 
				+ "=" + password);
		HttpResponse httpResponse = httpClient.execute(httpGet);
		if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
			String responseMessage = EntityUtils.toString(httpResponse.getEntity(),
					HTTP.UTF_8);
			Gson gson=new Gson();
			loginJson = gson.fromJson(responseMessage,LoginJson.class);
		}
		return loginJson;
	}
}

